package com.yituo.mjworld.mvc.dao;

import com.yituo.mjworld.core.utils.BaseDao;
import com.yituo.mjworld.mvc.entity.web.ProductProps;
import com.yituo.mjworld.mvc.entity.web.WebShopCut;
import org.springframework.stereotype.Repository;
import redis.clients.jedis.params.Params;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 购物车模块
 */
@Repository
public class ShopCatDao extends BaseDao {


  /**
   * 产品是否已经存在于用户的购物车当中
   *
   * @return
   */
  public WebShopCut getRecordProductIdAndUserId(int productId, String userId) {
    String hql = " from WebShopCut where productId=:productId and userId=:userId";
    Map<String,Object> params=new HashMap<String, Object>(2);
    params.put("productId",productId);
    params.put("userId",userId);
    List<WebShopCut> list = find(hql,params);
    if (list != null && list.size() > 0) {
      return list.get(0);
    }
    return null;
  }

  /**
   * 获取产品在后台定义的价格
   *
   * @param productId
   * @return
   */
  public String getTemplate(int productId) {
    String hql = "from ProductProps where productId=:productId and type=" + ProductProps.CAN_FLOAT;
    Map<String, Object> params = new HashMap<String, Object>(1);
    params.put("productId", productId);
    List<ProductProps> list = find(hql, params);
    ProductProps prop = null;
    if (list != null && list.size() > 0) {
      prop = list.get(0);
      return prop.getTemplate();
    }
    return null;
  }
}
